package cn.zhizihua.query;

import cn.zhizihua.pojo.Department;
import cn.zhizihua.pojo.Employee;
import cn.zhizihua.pojo.RegistLevel;
import cn.zhizihua.pojo.Role;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class EmployeeQuery extends BaseQuery{

    private String realname; //真实姓名 查询条件

    @Override
    public Wrapper getQueryWrapper() {
        //mp联查
        MPJLambdaWrapper<Employee> wrapper = new MPJLambdaWrapper<>();
        wrapper.setAlias("e") //设置别名
                .selectAll(Employee.class,"e") //查询全部
                .selectAs(Department::getDeptName,"'department.deptName'") //查询部门表信息
                .selectAs(RegistLevel::getRegistName,"'registLevel.registName'")
                .selectAs(Role::getName,"'role.name'")
                .leftJoin(Department.class,"d",Department::getId,Employee::getDeptmentId) //左连接部门表
                .leftJoin(RegistLevel.class,"r",RegistLevel::getId,Employee::getRegistLevelId)
                .leftJoin(Role.class,"ro",Role::getId,Employee::getRoleId)
                .orderByDesc("e.id"); //排序

        //搜索条件
        if (StringUtils.isNotEmpty(realname)){
            wrapper.like("e.realname",realname);
        }
        return wrapper;
    }


    /**
     * 患者挂号
     */
    private Integer scheduleIndex;  //班排下标 用于查询医生上班时间
    private Integer scheduleId; //班排id  scheduling_id
    private Integer deptmentId;  //所在科室id
    private Integer registLevelId; //挂号级别id
    private String roleName; //真实姓名
    private Long roleId; //Employee表 角色id

    public Wrapper<Employee> getConditionWrapper(){
        QueryWrapper<Employee> queryWrapper = new QueryWrapper();
        queryWrapper.eq("role_id",roleId)
                .eq("deptment_id",deptmentId)
                .eq("regist_level_id",registLevelId)
                .eq("scheduling_id",scheduleId);
        return queryWrapper;
    }
}
